package com.loe.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.EditText;

@SuppressLint("AppCompatCustomView")
public class ListEditText extends EditText
{
    public ListEditText(Context context)
    {
        super(context);
        init();
    }

    public ListEditText(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        init();
    }

    public ListEditText(Context context, AttributeSet attrs, int defStyleAttr)
    {
        super(context, attrs, defStyleAttr);
        init();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public ListEditText(Context context, AttributeSet attrs, int defStyleAttr, int
            defStyleRes)
    {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init()
    {
        addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
            {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
            {
            }

            @Override
            public void afterTextChanged(Editable editable)
            {
                if(textAfterListener != null) textAfterListener.onAfter(editable.toString());
            }
        });
    }

    public interface OnTextAfterListener
    {
        void onAfter(String s);
    }

    private OnTextAfterListener textAfterListener;

    public void setTextAfterListener(OnTextAfterListener textAfterListener)
    {
        this.textAfterListener = textAfterListener;
    }
}